package com.xxxx.controller;

import com.xxxx.entity.vo.MessageModel;
import com.xxxx.service.EditService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/edit")
public class EditServlet extends HttpServlet {
    private EditService editService = new EditService();
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        System.out.print(1);
        String uname = request.getParameter("uname");
        String upwd = request.getParameter("upwd");
        //String age1=request.getParameter("age");
        Integer age = Integer.parseInt(request.getParameter("age"));
        System.out.print(3);
        String uroom = request.getParameter("uroom");
        String usex = request.getParameter("usex");
        MessageModel messageModel = editService.userEdit(uname,upwd,age,uroom,usex);
        if(messageModel.getCode()==1){
            response.sendRedirect("login.jsp");
        }else{
            request.setAttribute("messageModel",messageModel);
            request.getRequestDispatcher("edit.jsp").forward(request,response);
        }
        System.out.print(-1);
    }
}
